package com.wysql.common;

import lombok.Data;

@Data
public class R<T> {
    private Integer code;
    private T data;

    public static <T> R<T> ok(T data) {
        R<T> apiResult = new R<>();
        apiResult.setCode(200);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> R<T> print(T data) {
        R<T> apiResult = new R<>();
        apiResult.setCode(9000);
        apiResult.setData(data);
        return apiResult;
    }

    // 123456789
    public static <T> R<T> printSuccessAndError(T data) {
        R<T> apiResult = new R<>();
        apiResult.setCode(9000);
        // type = import
        // type : importMsg , data: [正确,失败]
        apiResult.setData(data);
        return apiResult;
    }

    public static R<String> delete(int i) {
        R<java.lang.String> apiResult = new R<>();
        apiResult.setCode(9000);
        apiResult.setData("成功删除" + i + "条");
        return apiResult;
    }


    public static <T> R<T> ok() {
        R<T> apiResult = new R<>();
        apiResult.setCode(200);
        return apiResult;
    }


    public static <T> R<T> error(Integer code, T data) {
        R<T> apiResult = new R<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> R<T> error(T data) {
        R<T> apiResult = new R<>();
        apiResult.setCode(10000);
        apiResult.setData(data);
        return apiResult;
    }

}
